﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace StorageBox
{
    public class ShowMessageReader : ReaderViewBase
    {
        private Border _boxBorder;
        private Grid _rootElement;
        public ShowMessageReader(MainWindow main) : base(main)
        {
            _rootElement = main.MessageBackRoot;
            _boxBorder = main.MessageBackBorder;
        }

        /// <summary>
        /// 设置子元素
        /// </summary>
        public void SetChildElement(FrameworkElement element)
        {
            _boxBorder.Child = element;
        }

        public override void Show()
        {
            _rootElement.Visibility = Visibility.Visible;
            SY_Library.Animate.Begin<DoubleAnimation, double>(_rootElement, Grid.OpacityProperty, _rootElement.Opacity, 1, 500);
            BackplaneReader.Show(() =>
            {
                SY_Library.Animate.Begin<DoubleAnimation, double>(_rootElement, Grid.OpacityProperty, _rootElement.Opacity, 0, 500);
                Task.Run(() =>
                {
                    Task.Delay(600).Wait();
                    _rootElement.Dispatcher.Invoke(() => { _rootElement.Visibility = Visibility.Hidden; });
                });
            });
        }

        public override void Hide()
        {
            BackplaneReader.Hide();
        }
    }
}
